package com.xrit.controller;

import com.xrit.exception.CustomException;
import com.xrit.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice //controller的增强
public class BaseExceptionAdvice {

    //1.系统的异常
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception ex){
        return new Result(false,ex.getMessage());
    }

    //2.自定义的异常
    @ExceptionHandler(CustomException.class)
    public Result handlerException(CustomException ce){
        //发生了未知异常，请联系管理员...
        return new Result(false,ce.getMessage());
    }
}
